#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.basic.module.element.controller;

import ${package}.basic.module.element.service.ElementService;
import ${package}.common.bean.po.Element;
import ${package}.common.bean.vo.AddElementVo;
import ${package}.common.bean.vo.DisableOrEnableElementVo;
import ${package}.common.bean.vo.JsonResult;
import ${package}.common.bean.vo.QueryBean;
import ${package}.common.bean.vo.UpdateElementVo;
import ${package}.common.emum.ReturnCodeEnum;
import ${package}.common.utils.SnowFlakeUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Date;
import java.util.List;

/**
 * Description: 无法补充
 *
 * @author zhang wen yi
 * @date 2019/8/6 15:28
 *
 * <pre>
 *              ${copyright}
 *      Copyright (c) 2019. All Rights Reserved.
 * </pre>
 */
@Slf4j
@RestController
@RequestMapping("/yk_api/element/")
@AllArgsConstructor
@Api(value = "页面元素")
public class ElementController {
    /**
     * 元素Service
     */
    private ElementService elementService;

    /**
     * Description:
     * <查询页面元素列表>
     * @author pig
     * @date 16:19 2019/8/6
     * @param queryBean 1
     * @return JsonResult
     **/
    @PostMapping("queryElementByLimit")
    @ApiOperation(value = "查询页面元素列表",notes = "查询页面元素列表")
    @ApiImplicitParam(name = "queryBean",value = "查询条件",dataType = "QueryBean",paramType = "body",required = true)
    public JsonResult<PageInfo<Element>> queryElementByLimit(@RequestBody @Valid QueryBean queryBean){
        PageInfo<Element> pageInfo = elementService.queryElementByLimit(queryBean);
        return JsonResult.getInstant(ReturnCodeEnum.SUCCESS,pageInfo);
    }

    /**
     * Description:
     * <新增页面元素>
     * @author pig
     * @date 16:20 2019/8/6
     * @param addElementVo 1
     * @return JsonResult
     **/
    @PutMapping("addElement")
    @ApiOperation(value = "新增页面元素",notes = "新增页面元素")
    @ApiImplicitParam(name = "addElementVo",value = "新增页面元素实体类",dataType = "AddElementVo",paramType = "body")
    public JsonResult<Element> addElement(@RequestBody @Valid AddElementVo addElementVo){

        Element element = new Element();
        BeanUtils.copyProperties(addElementVo,element);

        element.setId(SnowFlakeUtil.getID());
        element.setCreatedate(new Date());
        elementService.addElement(element);

        return JsonResult.getInstant(ReturnCodeEnum.SUCCESS, element);
    }

    /**
     * Description:
     * <根据主键更新页面元素>
     * @author pig
     * @date 16:20 2019/8/6
     * @param updateElementVo 1
     * @return JsonResult
     **/
    @PostMapping("updateElementByKey")
    @ApiOperation(value = "根据主键更新页面元素",notes = "根据主键更新页面元素")
    @ApiImplicitParam(value = "更新页面元素实体类",name = "updateElementVo",paramType = "body",dataType = "UpdateElementVo",required = true)
    public JsonResult<Element> updateElementByKey(@RequestBody @Valid UpdateElementVo updateElementVo){

        Element element = new Element();
        BeanUtils.copyProperties(updateElementVo,element);

        elementService.updateElementByKey(element);
        return JsonResult.getInstant(ReturnCodeEnum.SUCCESS, element);
    }

    /**
     * Description:
     * <根据主键查询页面元素信息>
     * @author pig
     * @date 16:21 2019/8/6
     * @param id 1
     * @return JsonResult
     **/
    @ApiOperation(value = "根据主键查询页面元素信息",notes = "根据主键查询页面元素信息")
    @ApiImplicitParam(value = "页面元素主键",name = "id",paramType = "path",dataType = "Long",required = true)
    @GetMapping("queryElementByKey/{id}")
    public JsonResult<Element> queryElementByKey(@PathVariable("id") Long id){
        Element element = elementService.queryElementByKey(id);
        return JsonResult.getInstant(ReturnCodeEnum.SUCCESS,element);
    }

    /**
     * Description:
     * <根据主键删除页面元素>
     * @author pig
     * @date 16:21 2019/8/6
     * @param id 1
     * @return JsonResult
     **/
    @ApiOperation(value = "根据主键删除页面元素",notes = "根据主键删除页面元素")
    @DeleteMapping("deleteElementByKey/{id}")
    @ApiImplicitParam(name = "id",value = "页面元素主键",paramType = "path",dataType = "Long",required = true)
    public JsonResult<Long> deleteElementByKey(@PathVariable("id") Long id){
        elementService.deleteElementByKey(id);
        return JsonResult.getInstant(ReturnCodeEnum.SUCCESS, id);
    }


    /**
     * Description:
     * <批量删除页面元素>
     * @author pig
     * @date 16:22 2019/8/6
     * @param keys 1
     * @return JsonResult
     **/
    @ApiOperation(value = "批量删除页面元素",notes = "批量删除页面元素")
    @ApiImplicitParam(name = "keys",value = "页面元素主键数组",dataType = "Long",paramType = "body",allowMultiple = true,required = true)
    @PostMapping("removeElementsBykeys")
    public JsonResult<List<Element>> removeElementsBykeys(@RequestBody List<Long> keys){
        List<Element> elements = elementService.removeElementsBykeys(keys);
        return JsonResult.getInstant(ReturnCodeEnum.SUCCESS,elements);
    }

    /**
     * Description:
     * <禁用/启用>
     * @author pig
     * @date 16:22 2019/8/6
     * @param disableOrEnableElementVo 1
     * @return JsonResult
     **/
    @ApiOperation(value = "禁用/启用",notes = "禁用/启用")
    @PostMapping("disableOrEnableElement")
    @ApiImplicitParam(name = "disableOrEnableElementVo",value = "启用或禁用页面元素实体类",dataType = "DisableOrEnableElementVo",paramType = "body",required = true)
    public JsonResult<Element> disableOrEnableElement(@RequestBody @Valid DisableOrEnableElementVo disableOrEnableElementVo){

        Element element = new Element();
        BeanUtils.copyProperties(disableOrEnableElementVo,element);

        elementService.disableOrEnableElement(element);

        return JsonResult.getInstant(ReturnCodeEnum.SUCCESS, element);
    }

    /**
     * Description:
     * <查询编码是否重复>
     * @author pig
     * @date 16:22 2019/8/6
     * @param code 1
     * @param id 2
     * @return JsonResult
     **/
    @ApiOperation(value = "查询编码是否重复",notes = "查询编码是否重复")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code",value = "编码",paramType = "query",required = true),
            @ApiImplicitParam(name = "id",value = "主键",paramType = "query",dataType = "Long",required = true)})
    @GetMapping("elementVerifyCode")
    public JsonResult<Boolean> elementVerifyCode(@RequestParam("code") String code, @RequestParam("id") Long id){
        Boolean flag = elementService.elementVerifyCode(code, id);
        return JsonResult.getInstant(ReturnCodeEnum.SUCCESS,flag);
    }
}
